<?php

namespace Modules\Agent\Entities;

use Modules\Core\Entities\BaseEntity;
use ThrowException;
use Setting; 
use DB;

class AgentLevel extends BaseEntity
{
    protected $guarded = [];
    protected $table = 'agent_levels';
    static public $resourceName = '';

    protected $casts = [
        'brokerage_setting' => 'json',
    ];

    // 此等级下所有分销员
    public function agents()
    {
        return $this->hasMany('\Modules\Agent\Entities\Agent', 'agent_level_index',  'level');
    }

    public  function getBrokerageSettingAttribute($val)
    {
        return $val ? json_decode($val, true) : [
            [
                'node_type' => 'product',
                'node_type_text' => '普通商品',
                'is_enabled' => 0
            ],
            [
                'node_type' => 'box',
                'node_type_text' => '盲盒',
                'is_enabled' => 0
            ],
            [
                'node_type' => 'fudai',
                'node_type_text' => '福袋',
                'is_enabled' => 0
            ],
            [
                'node_type' => 'yifanshang',
                'node_type_text' => '一番赏',
                'is_enabled' => 0
            ]
        ];
    }

    // 是否是团队长
    public  function isAgentLeader()
    {
        return $this->level === 4;
    }
}
